home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 128 15 / q15.d81 / t.zero page 15 < prev    next >
Text File  |  2022-08-28  |  4KB  |  92 lines

  1.  
  2.               Z E R O    P A G E : PUTTING A DIRECTORY IN STRINGS
  3.  
  4.                                by Fender Tucker
  5.  
  6.  
  7.      Back in the old days programs that accessed the disk drive for files
  8. used to expect that the user knew which file he wanted to load.  The prompt
  9. would say, "Enter filename: ".  But then things got a little more
  10. sophisticated, especially when the C-128 came along, and then they'd say,
  11. "Enter filename (or press D for directory)".  This meant that instead of
  12. remembering filenames for hours or days, you only had to remember them for
  13. the few seconds it took to get back to the input prompt from looking at the
  14. directory.
  15.  
  16.      The only problem is that since filenames must be EXACT it's sometimes
  17. hard to remember a filename even for a few seconds.  That's why the current
  18. philosophy about filename requestors is that the program should read the
  19. disk directory and place the relevant filenames in a scrolling menu so the
  20. user only needs to highlight the filename he wants.  No typing is necessary.
  21. I doubt that anyone prefers the old way over the new way.
  22.  
  23.      There are two programs on this issue that have routines that read a
  24. directory then selectively put relevant filenames into string arrays.  I
  25. will describe them both and you can choose which one you prefer for your
  26. program.  They both should work on any type of drive, no matter what its 
  27. device number is.  These routines don't include the scrollable menu; they
  28. just put the filenames in subscripted strings for you, as the programmer, to
  29. handle as you wish.
  30.  
  31.      The first is from HURRICANE TRACKER, which is a BASIC 8 program and
  32. can't be LISTed without the BASIC 8 disk.  The routine looks like:
  33.  
  34.  2110 n=0:b$="":open2,dv,0,"$0:h.*"
  35.  2120 fori=1to36:get#2,a$:next
  36.  2130 get#2,a$:ifst<>0then2220
  37.  2140 ifa$<>chr$(34)then2130
  38.  2150 get#2,a$:ifst<>0then2220
  39.  2160 ifa$<>chr$(34)thenb$=b$+a$:goto2150
  40.  2170 n=n+1
  41.  2180 f$(n)=b$:b$=""
  42.  2190 get#2,a$:ifa$<>""then2190
  43.  2200 get#2,a$,a$,a$,a$
  44.  2210 ifst=0then2130
  45.  2220 close2
  46.  
  47. After this routine is invoked, all of the filenames on the disk that begin
  48. with "h." will be in f$(n), beginning with f$(1).  The variable n will hold
  49. the number of files found.  Note the use of wildcards in the OPEN command in
  50. line 2110.  If all files on the disk were wanted, then just "$" would be in
  51. quotes.  See your drive manual for more information about wildcards and how
  52. they can be used for selective directories.
  53.  
  54.      Line 2120 bypasses the header name.  The variable dv is the device
  55. number.  The rest of the code concerns using the double quotes -- chr$(34)
  56. -- that surround each filename.  The idea is to put what's between each open
  57. quote and close quote into f$(n), and throw away everything else.
  58.  
  59.      This routine will work in the 64 mode, too.  It's quite generic.
  60.  
  61.      The next routine is from Marshall Cook's EASY JACKET.  It's specific
  62. for the C-128 and uses some BASIC 7.0 commands.
  63.  
  64.  3100 n=0:b$="":b=65445:open2,dv,0,"$":sysdec("ffc6"),,2
  65.  3110 fori=1to4:sysb:next
  66.  3120 fori=1to2:sysb:next
  67.  3130 sysb:rrega:ifa=34thenff=1-ff:ifff=0then3150
  68.  3140 ifff=1thenb$=b$+chr$(a)
  69.  3150 ifa>0then3130
  70.  3160 f$(n)=b$:b$="":n=n+1:fori=1to2:sysb:next
  71.  3170 rregde:ifde>0then3120
  72.  3180 sysdec("ffcc"):close2:n=n-2
  73.  
  74. Both routines take the about the same amount of time, about a second per
  75. filename.  This second method places the header name into f$(0) while the
  76. first one doesn't.  Make sure you DIMension f$(n) large enough for your
  77. purposes.  1541 drives can hold 144 files, 1571's can hold 288, and 1581's
  78. can hold 296.  However, if there's a chance your program will need to handle
  79. over 100 filenames, it's probably time for an ML routine.  Making users wait
  80. 100 seconds for anything is not a 90's way to program.
  81.  
  82.      Programmers, consider using one of these routines (or a better version
  83. if you have one) in your programs and allow your users to choose files from
  84. a menu, rather than having to type in remembered filenames.  Some of us are
  85. getting too old to remember our anniversaries, much less filenames.
  86.  
  87.      I've placed a BASIC file called "dir stringers" on Side One that has
  88. these two routines in it.  Just delete the one you don't want and add the
  89. other to your program, renumbering if necessary.
  90.  
  91. FT
  92.                            **** End of Text ****